<template>
	<view class="content">
		<!-- <view style="position: absolute;z-index: 10076;background-color: #FFFFFF;width: 100%;"> -->
		<!-- <u-picker :show="showType" keyName="dict_label" :columns="typeList" closeOnClickOverlay
				@cancel="showType = false" @close="showType = false" @confirm="_setCurType"></u-picker> -->
		<u-popup :show="showType" mode="bottom" @close="close" @open="open">
			<view>
				<view @click="choose(item)" style="text-align: center;padding: 10px 0;font-size: 15px; color: #767676;" v-for="(item,index) in typeList" :key='index'>{{item.process_split}}</view>
			</view>
		</u-popup>
		<!-- </view> -->
		<view class="section-0">
			<view class="section-body">
				<view class="scbox">
					<view style="padding: 20px 0 0 20px;">
						<u-upload :fileList="fileList" :previewFullImage="true" @afterRead="afterRead"
							@delete="deletePic" multiple :maxCount="1">
						</u-upload>
						<view class="click_ip">点击上传照片</view>
					</view>
					<view class="picker" @click="showType = true">
						<text style="color:'#767676'">{{curType}}</text>
						<text class="iconfont icon-xiala"></text>
					</view>
				</view>

				<view class="box">
					<view style="padding-bottom: 10px;box-shadow: 0 0 20rpx 10rpx rgba(##f2eff2, 0.17);">
						<view class="name">图纸要求</view>
						<view class="body">
							<view class="item">
								<view class="name">{{list.drawing_require}}</view>
							</view>
						</view>
					</view>
					<view style="padding-bottom: 10px;box-shadow: 0 0 20rpx 10rpx rgba(##f2eff2, 0.17);">
						<view class="name">施工验收规范</view>
						<view class="body">
							<view class="item">
								<view class="name">{{list.acceptance_specification}}</view>
							</view>
						</view>
					</view>
				</view>
				<view style="height: 60px;"></view>
				<view class="dibu">
					<view class="jilu" @click="go()">记录</view>
					<view class="tijiao" @click="addTemplateApi()">提交</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getProjectTemplateInfoApi,
		getProjectProcessSplitApi,
		addTemplateApi
	} from '@/api/statistics.js';
	import { uploadUrl } from '@/baseUrl.js';
	export default {
		data() {
			return {
				picId:'',//图片id
				id: '',
				name: '',
				list: [],
				fileList: [],
				showType: false,
				curType: '请选择工序拆分', //模板
				curTypeId:'',
				selectedPeccancy: [],
				typeList: [],
				mrcurTypeId:'',
			}
		},
		methods: {
			async addTemplateApi(){
				uni.showLoading({
					mask:true
				})
				if(this.picId == ''){
					uni.showToast({
						title:'请上传照片',
						icon:'none',
						duration:500
					})
					return
				}
				let j = await addTemplateApi({
					process_photos: this.picId,
					id: this.curTypeId == '' ? this.mrcurTypeId : this.curTypeId
				})
				if(j.data.code == 1){
					uni.showToast({
						title:'提交成功',
						icon:'none',
						duration:1000
					})
				}
				uni.hideLoading()
			},
			choose(item){
				this.curType = item.process_split
				this.curTypeId = item.id
				this.close()
			},
			open() {
				// console.log('open');
			},
			close() {
				this.showType = false
				// console.log('close');
			},
			async getProjectTemplateInfoApi() {
				uni.showLoading({
					mask: true
				})
				let j = await getProjectTemplateInfoApi({
					id: this.id
				})
				console.log(j);
				if (j.data.code == 1) {
					this.list = j.data.data
					this.mrcurTypeId = this.list.id
				}
				uni.hideLoading()
			},
			async getProjectProcessSplitApi() {
				uni.showLoading({
					mask: true
				})
				let j = await getProjectProcessSplitApi({
					template_id: this.id
				})
				console.log(j.data.data);
				if (j.data.code == 0) {
					this.typeList = j.data.data
					 this.curType = this.typeList[0].process_split
				}
				uni.hideLoading()
			},
			go() {
				uni.navigateTo({
					url: 'demolistdetail?id=' + this.id
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList`].length
				lists.map((item) => {
					this[`fileList`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList`][fileListLen]
					this[`fileList`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result.data.file_id
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: uploadUrl, // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							this.picId = JSON.parse(res.data).data.file_id
							setTimeout(() => {
								resolve(JSON.parse(res.data))
							}, 1000)
						}
					});
				})
			},
		},
		onLoad(e) {
			this.id = e.id
			this.getProjectTemplateInfoApi()
			this.getProjectProcessSplitApi()
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #fafbfd;
	}

	.section-0 {
		width: 100%;
		background-color: #3a5df5;

		.section-body {
			width: 100%;
			padding-left: 40rpx;
			padding-right: 40rpx;
			padding-bottom: 50rpx;
			padding-top: 50rpx;
			background-color: #FFFFFF;
			background-size: cover;
			background-repeat: no-repeat;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			overflow: hidden;
			box-sizing: border-box;

			.title {
				font-size: 15px;
				color: #3a5df5;
				margin-top: -10px;
			}

			.scbox {
				width: 100%;
				height: 140px;
				display: flex;
				border-radius: 15px;
				box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
				margin-top: 10px;

				.picker {
					width: 60%;
					height: 48rpx;
					border-radius: 20rpx;
					border: solid 1rpx #ececec;
					background-color: #ececec;
					line-height: 44rpx;
					margin-top: 50px;
					margin-left: 10px;

					text {
						width: 10px;
						font-size: 26rpx;
						letter-spacing: 0rpx;
						color: #46464a;
						margin-left: 28rpx;
					}

					.iconfont {
						float: right;
						font-size: 32rpx;
						margin-right: 30rpx;
					}
				}

				.click_ip {
					font-size: 13px;
					margin: 0 0 10px 0;
					color: #919193;
				}
			}

			.box {
				width: 100%;
				border-radius: 15px;
				box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
				margin-top: 10px;

				.name {
					font-size: 15px;
					color: #3664ff;
					font-weight: bold;
					padding: 10px 0 10px 20px;
				}

				.body {
					width: 90%;
					margin-left: 5%;
					margin-right: 5%;
					background-color: #efefef;
					margin-bottom: 10px;
					@include clear;
					height: 150px;
					overflow-y: auto;

					.item {
						width: auto;
						height: 60rpx;
						@include clear();

						.name {
							float: left;
							width: calc(100% - 24rpx - 20rpx);
							font-size: 12px;
							font-weight: 300;
							padding: 15rpx 0;
							font-stretch: normal;
							line-height: 30rpx;
							font-stretch: normal;
							color: #827f82;
							letter-spacing: 1px;
							margin-left: 20rpx;
						}
					}
				}
			}

			.dibu {
				width: 100%;
				background-color: #FFFFFF;
				display: flex;
				justify-content: space-between;
				z-index: 10;
				position: fixed;
				bottom: 0;
				height: 50px;

				.jilu {
					width: 40%;
					height: 40px;
					background-color: #efefef;
					border-radius: 5px;
					line-height: 40px;
					text-align: center;
					font-size: 15px;
					color: #3d3e42;
				}

				.tijiao {
					width: 40%;
					height: 40px;
					background-color: #2e5eff;
					border-radius: 5px;
					line-height: 40px;
					text-align: center;
					font-size: 15px;
					color: #FFFFFF;
					margin-right: 10%;
				}
			}

			// .box1{
			// 	width: 100%;
			// 	border-radius: 15px;
			// 	box-shadow: 0 0 20rpx 10rpx rgba(#bcbcb5, 0.17);
			// 	margin-top: 10px;
			// 	.image{
			// 		width: 100px;
			// 		height: 100px;
			// 		padding: 12px;
			// 	}
			// 	.qutu{
			// 		width: 200px;
			// 		font-size: 13px;
			// 		overflow:hidden;
			// 		text-overflow:ellipsis;
			// 		white-space:nowrap;
			// 		color: #5b5b5e;
			// 		margin: 18px 0 0 0;
			// 	}
			// 	.qutu span{
			// 		color: #a3a3a3;
			// 		margin-left: 10px;
			// 	}
			// }
		}
	}
</style>
